package com.come4loves.game.module.fight.action;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.come4loves.game.module.battle.helper.PBConvertHelper;
import com.come4loves.game.module.fight.constants.FighterAttribute;
import com.come4loves.game.proto.BattleProto;
import com.google.protobuf.GeneratedMessage.Builder;

public class AttackAction extends Action {
	private int beAttackId;
	private Map<FighterAttribute, Integer> attackValue = new HashMap<FighterAttribute, Integer>();
	private Map<FighterAttribute, Integer> beAttackValue = new HashMap<FighterAttribute, Integer>();
	private Map<FighterAttribute, Boolean> attackValueFlag = new HashMap<FighterAttribute, Boolean>();
	private Map<FighterAttribute, Boolean> beAttackValueFlag = new HashMap<FighterAttribute, Boolean>();
	private int currentAttackerHP;
	private int currentBeAttackerHP;
	public AttackAction(int id) {
		super(id);
	}
	public AttackAction(int id, int beAttackId) {
		super(id);
		this.beAttackId = beAttackId;
		
	}
	public void putAttackValue(FighterAttribute attribute, int value, boolean flag){
		attackValue.put(attribute, value);
		attackValueFlag.put(attribute, flag);
	}
	public void putBeAttackValue(FighterAttribute attribute, int value, boolean flag){
		beAttackValue.put(attribute, value);
		beAttackValueFlag.put(attribute, flag);
	}
	
	public int getCurrentAttackerHP() {
		return currentAttackerHP;
	}
	public int getCurrentBeAttackerHP() {
		return currentBeAttackerHP;
	}
	public void setCurrentAttackerHP(int currentAttackerHP) {
		this.currentAttackerHP = currentAttackerHP;
	}
	public void setCurrentBeAttackerHP(int currentBeAttackerHP) {
		this.currentBeAttackerHP = currentBeAttackerHP;
	}
	
	
	
	public int getBeAttackId() {
		return beAttackId;
	}
	public Map<FighterAttribute, Integer> getAttackValue() {
		return attackValue;
	}
	public Map<FighterAttribute, Integer> getBeAttackValue() {
		return beAttackValue;
	}
	
	@Override
	public Builder<?> toProtocolBufferBuilder() {
		BattleProto.AttackAction.Builder builder = BattleProto.AttackAction.newBuilder();
		BattleProto.AttributeChangeData.Builder attDataBuilder = BattleProto.AttributeChangeData.newBuilder();
		attDataBuilder.setId((int) this.getId());
		for (Entry<FighterAttribute, Integer> entry : attackValue.entrySet()) {
			BattleProto.AttributeEntry.Builder b = BattleProto.AttributeEntry.newBuilder();
			b.setKey(PBConvertHelper.convertAttribute(entry.getKey()));
			b.setValue(entry.getValue());
			b.setFlag(attackValueFlag.get(entry.getKey()));
			attDataBuilder.addAttributeChange(b);
		}
		BattleProto.AttributeChangeData.Builder beAttdataBuilder = BattleProto.AttributeChangeData.newBuilder();
		beAttdataBuilder.setId((int) this.beAttackId);
		for (Entry<FighterAttribute, Integer> entry : beAttackValue.entrySet()) {
			BattleProto.AttributeEntry.Builder b = BattleProto.AttributeEntry.newBuilder();
			b.setKey(PBConvertHelper.convertAttribute(entry.getKey()));
			b.setValue(entry.getValue());
			b.setFlag(beAttackValueFlag.get(entry.getKey()));
			beAttdataBuilder.addAttributeChange(b);
		}
		builder.setAttackerData(attDataBuilder);
		builder.setBeAttackerData(beAttdataBuilder);
		return builder;
	}
	
	
	

}
